package operation;

import book.Book;
import book.Booklist;

import java.sql.SQLOutput;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024 —03 —04
 * Time: 20:56
 */
public class AddOperation implements IOPeration {


    @Override
    public void work(Booklist booklist) {
        System.out.println("新增图书");

        Scanner scanner =new Scanner(System.in);
        System.out.println("请输入书名");
        String name = scanner.nextLine();

        System.out.println("请输入作者");
        String author = scanner.nextLine();

        System.out.println("请输入价格");
        int price = scanner.nextInt();

        System.out.println("请输入类型");
        String type = scanner.nextLine();

        Book book = new Book(name,author,price,type);
        //检查数组当中有没有这本书
        int currentsize = booklist.getUsedsize();
        for (int i = 0; i < currentsize; i++) {
            Book book1 = booklist.getBook(i);
            if(book1.getName() == book.getName()){
                System.out.println("这本书已经存在，不进行存放了");
                return;
            }
        }
        if (currentsize == booklist.getBooks().length){
            System.out.println("书架满了!");
        }else {
            booklist.setBooks(currentsize,book);
            booklist.setUsedsize(currentsize+1);


        }


    }
}
